from collections import Counter

def topKFrequent(words,k):
    word_count=Counter(words)  #  Counter({.....}),可以计算出列表，元组，字符串中元素的个数,返回为字典类型
    sorted_words=sorted(word_count.keys(),key=lambda word:(-word_count[word],word))
    return sorted_words[:k]

word=input("请输入元素，空格隔开")
k=eval(input("请输入k值"))
words=word.split(' ')
print(topKFrequent(words,k))